<?php
/*由bean脚本生成 powerBy--joe*/
namespace app\common\model;

use app\common\bean\UserBean;
use app\common\bean\UserVipBean;

class UserVipModel extends BaseModel
{
	protected $table = 'user_vip';

    protected $append = ['is_validity'];

	/**
	* @return UserVipModel
	*/
	static function getInstance(){
		return parent::getInstance();
	}

    /** 所属用户
     * @return \think\model\relation\BelongsTo
     */
	public function user(){
	    return $this->belongsTo('UserModel',UserVipBean::$userId,UserBean::$id);
    }

    /**
     * @param $value
     * @param $data
     * @return bool
     */
    public function getIsValidityAttr($value,$data){
        if(time()>=strtotime($data[UserVipBean::$vipStartTime])&&time()<=strtotime($data[UserVipBean::$vipEndTime]))
            return true;
        return false;
    }
}
